package com.iwdm.renovation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.iwdm.renovation.databinding.ActivityChatItemBinding;

import java.util.List;


public class MyChatRecyclerViewAdapter extends RecyclerView.Adapter<MyChatRecyclerViewAdapter.ViewHolder> {

    private ActivityChatItemBinding binding;
    private List<Chat> list;

    public MyChatRecyclerViewAdapter(List<Chat> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        binding = ActivityChatItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        Chat chat = list.get(position);
        if (chat.isSend()) {
            holder.replay.setVisibility(View.GONE);
            holder.send.setText(chat.getMsg());
        } else {
            holder.send.setVisibility(View.GONE);
            holder.replay.setText(chat.getMsg());
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        public final View mView;
        public final Button replay;
        public final Button send;

        public ViewHolder(ActivityChatItemBinding binding) {
            super(binding.getRoot());
            mView = binding.getRoot();
            replay = binding.replay;
            send = binding.send;
        }
    }
}
